package com.bsoft.gol.hcs.specialist.service.impl;

import com.bsoft.gol.hcs.enumcase.FollowTypeEnum;
import com.bsoft.gol.hcs.enumcase.FollowUpRouteStatusEnum;
import com.bsoft.gol.hcs.enumcase.VisitRecordEnum;
import com.bsoft.gol.hcs.satisfaction.dao.PatientSatisfactionSurveyDAO;
import com.bsoft.gol.hcs.satisfaction.dao.SatisfactionProduceRecordDAO;
import com.bsoft.gol.hcs.satisfaction.entity.PatientSatisfactionSurvey;
import com.bsoft.gol.hcs.satisfaction.entity.SatisfactionProduceRecord;
import com.bsoft.gol.hcs.specialist.bean.ProduceFusStatement;
import com.bsoft.gol.hcs.specialist.dao.*;
import com.bsoft.gol.hcs.specialist.entity.*;
import com.bsoft.gol.hcs.utils.CommonUtils;
import com.bsoft.gol.hcs.visitrecord.dao.*;
import com.bsoft.gol.hcs.visitrecord.entity.VrApplicationFormRecord;
import com.bsoft.gol.hcs.visitrecord.entity.VrDispensingRecord;
import com.bsoft.gol.hcs.visitrecord.entity.VrInpatientVisitRecord;
import com.bsoft.gol.hcs.visitrecord.entity.VrSurgicalRecord;
import ctd.util.JSONUtils;
import ctd.util.KeyGenerator;
import hcn.base.VrOutpatientVisitRecord;
import hcn.enums.ItemTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.bsoft.gol.hcs.enumcase.VisitRecordEnum.*;

/**
 * 生成满意度调查随访计划
 *
 * @author neoLin - 2022/06/06 15:26
 **/
@Service
@Slf4j
public class ProduceSatisfactionSurveyPlanServiceImpl extends AbstractProducePlanService {

    @Value("${admin_user_id}")
    private String adminUserId;

    @Resource
    private FollowUpRouteDAO followUpRouteDAO;

    @Resource
    private FollowUpRouteDetailDAO followUpRouteDetailDAO;


    @Resource
    private FollowUpRouteDetailFormDAO followUpRouteDetailFormDAO;

    @Resource
    private VrInpatientVisitRecordDAO vrInpatientVisitRecordDAO;

    @Resource
    private VrOutpatientVisitRecordDAO vrOutpatientVisitRecordDAO;

    @Resource
    private PatientSatisfactionSurveyDAO patientSatisfactionSurveyDAO;

    @Resource
    private SatisfactionRequisitionRecordDAO satisfactionRequisitionRecordDAO;
    @Resource
    private VrSurgicalRecordDAO vrSurgicalRecordDAO;
    @Resource
    private VrApplicationFormRecordDAO vrApplicationFormRecordDAO;
    @Resource
    private VrDispensingRecordDAO vrDispensingRecordDAO;
    @Resource
    private SatisfactionProduceRecordDAO satisfactionProduceRecordDAO;
    @Resource
    private SatisfactionHealthEducationDAO satisfactionHealthEducationDAO;


    @Override
    public void producePlan() {
        //查询对应随访大类启用状态的随访路径列表
        //随访大类类型 1-专病随访，2-院后随访，3-满意度随访
        List<FollowUpRoute> followUpRoutes =
                followUpRouteDAO.queryByFollowTypeAndStatus(FollowTypeEnum.FUS_SATISFACTION.getType(),
                        FollowUpRouteStatusEnum.ENABLE.getStatus());
        log.info("----followUpRoutes---->>>"+followUpRoutes.listIterator().toString()+followUpRoutes.size());
        if (!CommonUtils.isEmpty(followUpRoutes)){

            followUpRoutes.forEach(followUpRoute -> {
                produce(followUpRoute,adminUserId);
            });
        }
    }

    @Override
    public void produce(FollowUpRoute followUpRoute, String operatorId){
        ProduceFusStatement statement = new ProduceFusStatement();
        statement.setFollowUpRoute(followUpRoute);
        statement.setOperatorId(operatorId);
        statement.setOrganizationId(followUpRoute.getOrganizationId());
        log.info("--------statement------>"+statement);
        doProduceExecutionList(statement);
    }


    @Override
    public void handleForOutpatient(ProduceFusStatement statement, String patientId, String departmentId) {

        VrOutpatientVisitRecord vrOutpatientVisitRecord =
                vrOutpatientVisitRecordDAO.getByPatientIdAndLastOne(patientId, departmentId);
        if (Objects.isNull(vrOutpatientVisitRecord)) {
            return;
        }
        String businessId = vrOutpatientVisitRecord.getVisitRecordId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(OUTPATIENT_VISIT_RECORD, businessId, routeDetailId);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, vrOutpatientVisitRecord.getStartTime());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, vrOutpatientVisitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }


    @Override
    public void handleForInpatient(ProduceFusStatement statement, String patientId, String departmentId) {
        VrInpatientVisitRecord visitRecord =
                vrInpatientVisitRecordDAO.getByPatientIdAndLastOne(patientId, departmentId);
        log.info("---followUpRoute-->"+ JSONUtils.writeValueAsString(visitRecord) );
        if (Objects.isNull(visitRecord)) {
            return;
        }
        String businessId = visitRecord.getHospitalRecordId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(INPATIENT_VISIT_RECORD, businessId, routeDetailId);
        log.info("--------------needProduce----->"+needProduce);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, visitRecord.getDischargeTime());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, visitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }

    @Override
    public void handleForInspectionForm(ProduceFusStatement statement, String patientId, String departmentId) {
        VrApplicationFormRecord visitRecord =
                vrApplicationFormRecordDAO.getPatientIdAndLastOne(patientId, "1", departmentId);

        if (Objects.isNull(visitRecord)) {
            return;
        }
        String businessId = visitRecord.getApplicationId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(INSPECTION_RECORD, businessId, routeDetailId);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, visitRecord.getApplicationTime());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, visitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }

    @Override
    public void handleForCheckForm(ProduceFusStatement statement, String patientId, String departmentId) {
        VrApplicationFormRecord visitRecord =
                vrApplicationFormRecordDAO.getPatientIdAndLastOne(patientId, "2", departmentId);
        if (Objects.isNull(visitRecord)) {
            return;
        }
        String businessId = visitRecord.getApplicationId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(CHECK_RECORD, businessId, routeDetailId);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, visitRecord.getApplicationTime());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, visitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }

    @Override
    public void handleForTreatmentForm(ProduceFusStatement statement, String patientId, String departmentId) {
        VrApplicationFormRecord visitRecord =
                vrApplicationFormRecordDAO.getPatientIdAndLastOne(patientId, "3", departmentId);
        if (Objects.isNull(visitRecord)) {
            return;
        }
        String businessId = visitRecord.getApplicationId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(TREATMENT_RECORD, businessId, routeDetailId);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, visitRecord.getApplicationTime());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, visitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }


    @Override
    public void handleForDispensing(ProduceFusStatement statement, String patientId, String departmentId) {
        VrDispensingRecord visitRecord = vrDispensingRecordDAO.getPatientIdAndLastOne(patientId, departmentId);
        if (Objects.isNull(visitRecord)) {
            return;
        }
        String businessId = visitRecord.getDistributionId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(SURGICAL_RECORD, businessId, routeDetailId);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, visitRecord.getDispensingDate());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, visitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }

    @Override
    public void handleForSurgical(ProduceFusStatement statement, String patientId, String departmentId) {
        VrSurgicalRecord visitRecord = vrSurgicalRecordDAO.getPatientIdAndLastOne(patientId, departmentId);
        if (Objects.isNull(visitRecord)) {
            return;
        }
        String businessId = visitRecord.getOperationRecordId();
        Long routeDetailId = statement.getFollowUpRouteDetail().getRouteDetailId();
        boolean needProduce = needProduce(SURGICAL_RECORD, businessId, routeDetailId);
        if (needProduce) {
            //保存满意度计划
            PatientSatisfactionSurvey insert = genPatientSatisfactionSurvey(statement, businessId, patientId, visitRecord.getStartTime());
            String recordId = insert.getPatientSurveyId();
            savePatientSatisfactionSurvey(insert, visitRecord);
            //保存满意度表单
            saveSatisfactionForm(statement, recordId);
            //保存因素使用记录
            saveFusFactorDataRecord(statement, patientId, recordId);
            //保存生成记录
            saveProduceRecord(statement, businessId, recordId);
        }
    }


    /**
     * 保存生成记录
     */
    private void saveProduceRecord(ProduceFusStatement statement, String businessId, String recordId) {
        FollowUpRoute followUpRoute = statement.getFollowUpRoute();

        SatisfactionProduceRecord insert = new SatisfactionProduceRecord();
        insert.setBusinessType(followUpRoute.getVisitType().toString());
        insert.setBusinessId(businessId);
        insert.setPatientSurveyId(recordId);
        insert.setRouteId(followUpRoute.getRouteId());
        insert.setRouteDetailId(statement.getFollowUpRouteDetail().getRouteDetailId());
        insert.setCreatorId(statement.getOperatorId());
        insert.setGmtCreate(new Date());

        satisfactionProduceRecordDAO.save(insert);

    }

    /**
     * 保存满意度表单
     *
     * @param recordId 满意度计划主键
     */
    private void saveSatisfactionForm(ProduceFusStatement statement, String recordId) {

        List<FollowUpRouteDetailForm> forms = statement.getFollowUpRouteDetailForms();
        if (CollectionUtils.isEmpty(forms)) {
            return;
        }
        Date now = new Date();
        //保存表单
        List<SatisfactionRequisitionRecord> insertList =
                forms.stream().filter(form -> ItemTypeEnum.FORM.getType().equals(form.getItemType()))
                        .map(form -> {
                            SatisfactionRequisitionRecord insert = new SatisfactionRequisitionRecord();
                            insert.setFormId(KeyGenerator.randomGenerate());
                            insert.setRecordId(recordId);
                            insert.setCreateId(statement.getOperatorId());
                            insert.setExecuteId("");
                            insert.setExecuteName("");
                            insert.setCreateDt(now);
                            insert.setModifyDt(now);
                            insert.setQuestionnaireId(form.getFormRecordId());
                            insert.setQuestionnaireName(form.getFormName());
                            return insert;
                        }).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(insertList)) {
            insertList.forEach(i->satisfactionRequisitionRecordDAO.insertSelective(i));
        }
        List<SatisfactionHealthEducation> insertList2 =
                forms.stream().filter(form -> ItemTypeEnum.EDUCATION.getType().equals(form.getItemType()))
                        .map(form -> {
                            SatisfactionHealthEducation insert = new SatisfactionHealthEducation();
                            insert.setId(KeyGenerator.randomGenerate());
                            insert.setRecordId(recordId);
                            insert.setEducationId(form.getEducationId());
                            insert.setEducationName(form.getEducationName());
                            insert.setDefaultPush(0);
                            insert.setCreateDt(now);
                            insert.setModifyDt(now);

                            return insert;
                        }).collect(Collectors.toList());
        //保存健康宣教
        if (!CollectionUtils.isEmpty(insertList2)) {
            insertList2.forEach(i->satisfactionHealthEducationDAO.insertSelective(i));
        }
    }

    /**
     * 生成满意度调查计划数据
     *
     * @param businessId 业务关联主键
     */
    private PatientSatisfactionSurvey genPatientSatisfactionSurvey(ProduceFusStatement statement, String businessId,
                                                                   String patientId, Date recordDate) {
        Date now = new Date();
        String id = KeyGenerator.randomGenerate();
        FollowUpRouteDetail followUpRouteDetail = statement.getFollowUpRouteDetail();
        FollowUpRoute followUpRoute = statement.getFollowUpRoute();

        //计算随访计划时间
        Date planTime = getStartPlanTime(statement, patientId, recordDate);

        PatientSatisfactionSurvey insert = new PatientSatisfactionSurvey();
        insert.setRouteDetailType(followUpRouteDetail.getRouteDetailType());
        insert.setPlanSurveyTime(planTime);
        insert.setPlanTime(planTime);
        insert.setPatientSurveyId(id);
        insert.setIsNotify(followUpRouteDetail.getIsNotify().toString());
        insert.setProcessingStatus("0");
        insert.setCreatorId(statement.getOperatorId());
        insert.setGmtCreate(now);
        insert.setModifyId(statement.getOperatorId());
        insert.setGmtModified(now);
        insert.setSurveyStatus("0");
        insert.setNotifyStatus("0");
        insert.setSurveyRuleId(followUpRoute.getRouteId());
        insert.setSurveyRuleName(followUpRoute.getRouteName());
        //居民对处理结果的确认状态 1：已确认   0：未确认
        insert.setConfirmStatus("0");
        insert.setBusinessId(businessId);
        insert.setBusinessType(followUpRoute.getVisitType().toString());

        if(CommonUtils.isNotEmpty(statement.getFollowUpRouteDetailForms())){
            FollowUpRouteDetailForm followUpRouteDetailForm = statement.getFollowUpRouteDetailForms().get(0);
            if (CommonUtils.isNotEmpty(1==followUpRouteDetailForm.getItemType())) {
                insert.setQuestionnaireId(followUpRouteDetailForm.getFormRecordId());
                insert.setQuestionnaireName(followUpRouteDetailForm.getFormName());
            }
        }

        insert.setSurveySource("1");
        return insert;
    }


    /**
     * 生成满意度随访计划
     */
    public void doProduceExecutionList(ProduceFusStatement statement) {
        //查询随访路径子路径列表
        FollowUpRoute followUpRoute = statement.getFollowUpRoute();
        List<FollowUpRouteDetail> followUpRouteDetails =
                followUpRouteDetailDAO.queryByRouteId(followUpRoute.getRouteId());
        log.info("---followUpRouteDetails---->"+followUpRouteDetails.size()+followUpRouteDetails.listIterator());
        if (!CollectionUtils.isEmpty(followUpRouteDetails)) {
            for (FollowUpRouteDetail followUpRouteDetail :
                    followUpRouteDetails) {
                statement.setFollowUpRouteDetail(followUpRouteDetail);
                dealFollowUpRouteDetail(statement);
            }
        }
    }


    /**
     * 处理随访路径详情
     */
    private void dealFollowUpRouteDetail(ProduceFusStatement statement) {
            log.info("-------statement------>"+statement);
        FollowUpRouteDetail followUpRouteDetail = statement.getFollowUpRouteDetail();
        log.info("---followUpRouteDetail-->"+ JSONUtils.writeValueAsString(followUpRouteDetail) );
        FollowUpRoute followUpRoute = statement.getFollowUpRoute();
        log.info("---followUpRoute-->"+ JSONUtils.writeValueAsString(followUpRoute) );
        List<String> previousList = handleFollowUpRouteDetail(statement);
        log.info("---previousList-->"+ JSONUtils.writeValueAsString(previousList) );
        //随访提前通知时间-天数
        Integer advanceNotifyDate = getAdvanceNotifyDate(followUpRouteDetail);
        log.info("---advanceNotifyDate-->"+ JSONUtils.writeValueAsString(advanceNotifyDate) );
        if (Objects.isNull(advanceNotifyDate)) {
            return;
        }
        statement.setAdvanceNotifyDate(advanceNotifyDate);
        List<FollowUpRouteDetailForm> followUpRouteDetailForms =
                followUpRouteDetailFormDAO.queryByRouteDetailId(followUpRouteDetail.getRouteDetailId());
        log.info("---followUpRouteDetailForms-->"+ JSONUtils.writeValueAsString(followUpRouteDetailForms) );
        statement.setFollowUpRouteDetailForms(followUpRouteDetailForms);

        log.info("----for---statement------>"+statement);
        log.info("-------->"+previousList.listIterator()+previousList.size()+"=========");
        for (String patientId :
                previousList) {
            //根据就诊类型查询对应的就诊类型记录
            VisitRecordEnum visitType = getEnumByKey(followUpRoute.getVisitType());

            log.info("---------------------------------------------------------------visitType"+visitType);
            String departmentId = followUpRoute.getDepartmentId();
            switch (visitType) {
                case OUTPATIENT_VISIT_RECORD:
                    handleForOutpatient(statement, patientId, departmentId);
                    break;
                case INPATIENT_VISIT_RECORD:
                    log.info("-----------住院记录---------------"+INPATIENT_VISIT_RECORD);
                    handleForInpatient(statement, patientId, departmentId);
                    break;
                case PHYSICAL_EXAMINATION_RECORDS:
                    break;
                case SURGICAL_RECORD:
                    handleForSurgical(statement, patientId, departmentId);
                    break;
                case INSPECTION_RECORD:
                    handleForInspectionForm(statement, patientId, departmentId);
                    break;
                case CHECK_RECORD:
                    handleForCheckForm(statement, patientId, departmentId);
                    break;
                case DISPENSING_RECORD:
                    handleForDispensing(statement, patientId, departmentId);
                    break;
                case TREATMENT_RECORD:
                    handleForTreatmentForm(statement, patientId, departmentId);
                    break;
                default:
                    break;
            }
        }
    }


    /**
     * 保存满意度调查计划 (取药/发药)
     *
     * @author tongtp 2020/9/7 16:14
     */
    private void savePatientSatisfactionSurvey(PatientSatisfactionSurvey patientSatisfactionSurvey,
                                               VrDispensingRecord record) {
        patientSatisfactionSurvey.setOrganizationId(record.getOrganizationId());
        patientSatisfactionSurvey.setOrganizationName(record.getOrganizationName());
        patientSatisfactionSurvey.setDepartmentId(record.getDepartmentId());
        patientSatisfactionSurvey.setDepartmentName(record.getDepartmentName());
        patientSatisfactionSurvey.setDoctorId(record.getDoctorId());
        patientSatisfactionSurvey.setDoctorName(record.getDoctorName());
        patientSatisfactionSurvey.setPatientId(record.getPatientId());
        patientSatisfactionSurvey.setCardType(record.getCardType());
        patientSatisfactionSurvey.setCardNumber(record.getCardNumber());
        patientSatisfactionSurvey.setPatientMedicalCardType(record.getPatientMedicalCardType());
        patientSatisfactionSurvey.setPatientMedicalCardNumber(record.getPatientMedicalCardNumber());
        patientSatisfactionSurvey.setPatientName(record.getPatientName());
        patientSatisfactionSurvey.setPatientBirthday(record.getPatientBirthday());
        patientSatisfactionSurvey.setPatientSex(record.getPatientSex());
        patientSatisfactionSurvey.setPatientAge(record.getPatientAge());
        patientSatisfactionSurvey.setTelephone(record.getTelephone());
        patientSatisfactionSurvey.setAddress(record.getAddress());
        patientSatisfactionSurvey.setCompanionName(record.getCompanionName());
        patientSatisfactionSurvey.setCompanionPhone(record.getCompanionPhone());
        patientSatisfactionSurvey.setRelation(record.getCompanionRelationship());
        patientSatisfactionSurveyDAO.insertSelective(patientSatisfactionSurvey);
    }

    /**
     * 保存满意度调查计划 (治疗记录,处置记录)
     *
     * @author tongtp 2020/9/7 16:14
     */
    private void savePatientSatisfactionSurvey(PatientSatisfactionSurvey patientSatisfactionSurvey,
                                               VrApplicationFormRecord record) {
        patientSatisfactionSurvey.setOrganizationId(record.getOrganizationId());
        patientSatisfactionSurvey.setOrganizationName(record.getOrganizationName());
        patientSatisfactionSurvey.setDepartmentId(record.getOpenDepartmentId());
        patientSatisfactionSurvey.setDepartmentName(record.getOpenDepartmentName());
        patientSatisfactionSurvey.setDoctorId(record.getOpenDoctorId());
        patientSatisfactionSurvey.setDoctorName(record.getOpenDoctorName());
        patientSatisfactionSurvey.setPatientId(record.getPatientId());
        patientSatisfactionSurvey.setCardType(record.getCardType());
        patientSatisfactionSurvey.setCardNumber(record.getCardNumber());
        patientSatisfactionSurvey.setPatientMedicalCardType(record.getPatientMedicalCardType());
        patientSatisfactionSurvey.setPatientMedicalCardNumber(record.getPatientMedicalCardNumber());
        patientSatisfactionSurvey.setPatientName(record.getPatientName());
        patientSatisfactionSurvey.setPatientBirthday(record.getPatientBirthday());
        patientSatisfactionSurvey.setPatientSex(record.getPatientSex());
        patientSatisfactionSurvey.setPatientAge(record.getPatientAge());
        patientSatisfactionSurvey.setTelephone(record.getTelephone());
        patientSatisfactionSurvey.setAddress(record.getAddress());
        patientSatisfactionSurvey.setCompanionName(record.getCompanionName());
        patientSatisfactionSurvey.setCompanionPhone(record.getCompanionPhone());
        patientSatisfactionSurvey.setRelation(record.getCompanionRelationship());
        patientSatisfactionSurveyDAO.insertSelective(patientSatisfactionSurvey);
    }

    /**
     * 保存满意度调查计划 (手术记录)
     *
     * @author tongtp 2020/9/7 16:14
     */
    private void savePatientSatisfactionSurvey(PatientSatisfactionSurvey patientSatisfactionSurvey,
                                               VrSurgicalRecord record) {
        patientSatisfactionSurvey.setOrganizationId(record.getOrganizationId());
        patientSatisfactionSurvey.setOrganizationName(record.getOrganizationName());
        patientSatisfactionSurvey.setDepartmentId(record.getDepartmentId());
        patientSatisfactionSurvey.setDepartmentName(record.getDepartmentName());
        patientSatisfactionSurvey.setDoctorId(record.getSurgeonDoctorId());
        patientSatisfactionSurvey.setDoctorName(record.getSurgeonDoctorName());
        patientSatisfactionSurvey.setPatientId(record.getPatientId());
        patientSatisfactionSurvey.setCardType(record.getCardType());
        patientSatisfactionSurvey.setCardNumber(record.getCardNumber());
        patientSatisfactionSurvey.setPatientMedicalCardType(record.getPatientMedicalCardType());
        patientSatisfactionSurvey.setPatientMedicalCardNumber(record.getPatientMedicalCardNumber());
        patientSatisfactionSurvey.setPatientName(record.getPatientName());
        patientSatisfactionSurvey.setPatientBirthday(record.getPatientBirthday());
        patientSatisfactionSurvey.setPatientSex(record.getPatientSex());
        patientSatisfactionSurvey.setPatientAge(record.getPatientAge());
        patientSatisfactionSurvey.setTelephone(record.getTelephone());
        patientSatisfactionSurvey.setAddress(record.getAddress());
        patientSatisfactionSurvey.setCompanionName(record.getCompanionName());
        patientSatisfactionSurvey.setCompanionPhone(record.getCompanionPhone());
        patientSatisfactionSurvey.setRelation(record.getCompanionRelationship());
        patientSatisfactionSurveyDAO.insertSelective(patientSatisfactionSurvey);
    }

    /**
     * 保存满意度调查计划 (住院)
     *
     * @author tongtp  2020/9/7 16:14
     */
    private void savePatientSatisfactionSurvey(PatientSatisfactionSurvey patientSatisfactionSurvey,
                                               VrInpatientVisitRecord record) {
        patientSatisfactionSurvey.setOrganizationId(record.getOrganizationId());
        patientSatisfactionSurvey.setOrganizationName(record.getOrganizationName());
        patientSatisfactionSurvey.setDepartmentId(record.getDepartmentId());
        patientSatisfactionSurvey.setDepartmentName(record.getDepartmentName());
        patientSatisfactionSurvey.setDoctorId(record.getAttendingDoctorId());
        patientSatisfactionSurvey.setDoctorName(record.getAttendingDoctorName());
        patientSatisfactionSurvey.setPatientId(record.getPatientId());
        patientSatisfactionSurvey.setCardType(record.getCardType());
        patientSatisfactionSurvey.setCardNumber(record.getCardNumber());
        patientSatisfactionSurvey.setPatientMedicalCardType(record.getPatientMedicalCardType());
        patientSatisfactionSurvey.setPatientMedicalCardNumber(record.getPatientMedicalCardNumber());
        patientSatisfactionSurvey.setPatientName(record.getPatientName());
        patientSatisfactionSurvey.setPatientBirthday(record.getPatientBirthday());
        patientSatisfactionSurvey.setPatientSex(record.getPatientSex());
        patientSatisfactionSurvey.setPatientAge(record.getPatientAge());
        patientSatisfactionSurvey.setTelephone(record.getTelephone());
        patientSatisfactionSurvey.setAddress(record.getAddress());
        patientSatisfactionSurvey.setCompanionName(record.getCompanionName());
        patientSatisfactionSurvey.setCompanionPhone(record.getCompanionPhone());
        patientSatisfactionSurvey.setRelation(record.getCompanionRelationship());
        patientSatisfactionSurvey.setHospitalNumber(record.getInHospitalRecordNumber());
        patientSatisfactionSurveyDAO.insertSelective(patientSatisfactionSurvey);
    }

    /**
     * 保存满意度调查计划  (门诊)
     *
     * @author tongtp 2020/9/7 16:14
     */
    private void savePatientSatisfactionSurvey(PatientSatisfactionSurvey patientSatisfactionSurvey,
                                               VrOutpatientVisitRecord record) {
        patientSatisfactionSurvey.setOrganizationId(record.getOrganizationId());
        patientSatisfactionSurvey.setOrganizationName(record.getOrganizationName());
        patientSatisfactionSurvey.setDepartmentId(record.getDepartmentId());
        patientSatisfactionSurvey.setDepartmentName(record.getDepartmentName());
        patientSatisfactionSurvey.setDoctorId(record.getDoctorId());
        patientSatisfactionSurvey.setDoctorName(record.getDoctorName());
        patientSatisfactionSurvey.setPatientId(record.getPatientId());
        patientSatisfactionSurvey.setCardType(record.getCardType());
        patientSatisfactionSurvey.setCardNumber(record.getCardNumber());
        patientSatisfactionSurvey.setPatientMedicalCardType(record.getPatientMedicalCardType());
        patientSatisfactionSurvey.setPatientMedicalCardNumber(record.getPatientMedicalCardNumber());
        patientSatisfactionSurvey.setPatientName(record.getPatientName());
        patientSatisfactionSurvey.setPatientBirthday(record.getPatientBirthday());
        patientSatisfactionSurvey.setPatientSex(record.getPatientSex());
        patientSatisfactionSurvey.setPatientAge(record.getPatientAge());
        patientSatisfactionSurvey.setTelephone(record.getTelephone());
        patientSatisfactionSurvey.setAddress(record.getAddress());
        patientSatisfactionSurvey.setCompanionName(record.getCompanionName());
        patientSatisfactionSurvey.setCompanionPhone(record.getCompanionPhone());
        patientSatisfactionSurvey.setRelation(record.getCompanionRelationship());

        patientSatisfactionSurveyDAO.insertSelective(patientSatisfactionSurvey);
    }


}



